package com.appspot.javametronome.client.view.widget;

import com.appspot.javametronome.client.controller.BpmController;
import com.appspot.javametronome.client.controller.TickController;
import com.google.gwt.user.client.ui.PushButton;

public class TapInButton extends PushButton implements GroupableButton {
    
    private static String text = "Tap In";
    private ButtonGroup group;
    private boolean selected = false;

    public TapInButton() {
        super(text);
    }
    
    @Override
    public void setButtonGroup(ButtonGroup group) {
        this.group = group;
    }
    
    @Override
    public void onClickStart() {
        super.onClickStart();
        if (!this.selected) {
            group.selectButton(this);
        }
        TickController.instance.playOnce();
        BpmController.instance.onTap();
    }

    @Override
    public void setSelected() {
        if (!selected) {
            selected = true;
            TickController.instance.stop();
            BpmController.instance.refresh();
        }
    }

    @Override
    public void setUnselected() {
        if (selected) {
            selected = false;
            BpmController.instance.refresh();
        }
    }

}
